package com.xiaoxx.common.intercepter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author :HX
 * @date : 2023/7/19
 * 拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Bean
    public AdminInterceptor adminInterceptor() {
        return new AdminInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册Interceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(adminInterceptor());
        //所有路径都被拦截
        registration.addPathPatterns("/**");
        //添加不拦截路径
        //gitee 回调
        registration.excludePathPatterns("/api/sys/user/gitee/callback", "/api/sys/user/gitee/url");
        registration.excludePathPatterns("/api/sys/user/user/gitee/callback");
        //swagger
        registration.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/doc.html/**", "/favicon.ico", "/v3/**");
        //登录
        registration.excludePathPatterns("/api/sys/user/login");
        //注册
        registration.excludePathPatterns("/api/sys/user/register");
        //验证码
        registration.excludePathPatterns("/api/sys/user/getCode");
        //创建sse链接
        registration.excludePathPatterns("/api/chat/addSse");
        //创建sse链接
        registration.excludePathPatterns("/api/sys/user/getIpInfo");
        //websocket
        registration.excludePathPatterns("/websocket/**");
    }
}
